<?php
if( !defined('CORE') ) exit('Request Error!');
/**
 * @author yangzhi
 * 上传文件管理
 */
class mod_upload
{
    /**
     * 上传图片到uploads/img/tmp目录
     * 后面表单提交后记得将图片移动到对应日期的目录中去
     */
    public static function move_img($img_name)
    {
        if(!$img_name)
        {
            return '';
        }
        $basename = basename($img_name);
        $tmp_path = PATH_UPLOADS . "/img/tmp/";

        if(!file_exists($tmp_path . $basename))
        {
            return '';
        }

        $date = strrchr(dirname($img_name), "/");

        $file_path = PATH_UPLOADS . '/img' . $date . '/';
        util::path_exists($file_path);
        $res = rename($tmp_path . $basename, $file_path . $basename);

        return $res;
    }
    /**
     * 上传文件到uploads/file/tmp目录
     * 后面表单提交后记得将文件移动到对应日期的目录中去
     */
    public static function move_file($file_name)
    {
        if(!$file_name)
        {
            return '';
        }
        $basename = basename($file_name);
        $tmp_path = PATH_UPLOADS . "/file/tmp/";

        if(!file_exists($tmp_path . $basename))
        {
            return '';
        }

        $date = strrchr(dirname($file_name), "/");

        $file_path = PATH_UPLOADS . '/file' . $date . '/';
        util::path_exists($file_path);
        $res = rename($tmp_path . $basename, $file_path . $basename);

        return $res;
    }
}


